package com.shisan.tingshu.account.mapper;

import com.shisan.tingshu.model.account.UserAccount;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;

import java.math.BigDecimal;

@Mapper
public interface UserAccountMapper extends BaseMapper<UserAccount> {

    /**
     * 判断余额是否充足并修改余额
     * @param userId
     * @param amount
     * @return
     */
    int checkAndLockAmount(@Param("userId") Long userId, @Param("amount") BigDecimal amount);

    /**
     * 解锁“锁定金额返回对象”
     * @param userId
     * @param amount
     * @return
     */
    int unLock(@Param("userId") Long userId, @Param("amount") BigDecimal amount);

    /**
     * 消费
     * @param userId
     * @param amount
     * @return
     */
    int minus(@Param("userId") Long userId, @Param("amount") BigDecimal amount);

    /**
     * 修改用户账户的余额信息
     * @param userId
     * @param rechargeAmount
     * @return
     */
    int updateUserAccount(@Param("userId") String userId, @Param("amount") BigDecimal rechargeAmount);
}
